﻿@model ConfigureThemeModel

@{
    ViewBag.Title = T("Admin.Configuration.Themes.Title", Model.ThemeName);
    string parsingError = (string)TempData["SassParsingError"];
}

<form asp-action="Configure" method="post">
    <input type="hidden" name="theme" value="@Model.ThemeName" />
    <div class="multi-store-scope well border p-0">
        <div class="adminContent adminContent-boxed">
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="StoreId"/>
                </div>
                <div class="adminData">
                    <select asp-for="StoreId" asp-items="Model.AvailableStores" onchange="location.href='@(ViewData["ConfigureThemeUrl"])&storeId=' + this.value;"></select>
                </div>
            </div>
        </div>
    </div>

    <div class="section-header">
        <div class="title">
            <a sm-backto asp-action="List" asp-route-storeId="@Model.StoreId"></a>
            <i class="fa fa-paint-brush"></i>
            <span>@ViewBag.Title</span>
        </div>
        <div class="options">
            <zone name="admin_button_toolbar_before"></zone>

            <button type="submit" name="save" value="save" class="btn btn-warning">
                <i class="fa fa-check"></i>
                <span>@T("Admin.Common.Save")</span>
            </button>
            <button type="submit" name="save" value="save-continue" class="btn btn-secondary">
                <span>@T("Admin.Common.SaveContinue")</span>
            </button>
            <a href="#importvariables-window" data-toggle="modal" class="btn btn-secondary">
                <i class="far fa-circle-up"></i>
                <span>@T("Common.Import")</span>
            </a>
            <a href="#exportvariables-window" data-toggle="modal" class="btn btn-secondary">
                <i class="far circle-down"></i>
                <span>@T("Common.Export")</span>
            </a>
            <button type="submit" class="btn btn-danger confirm" name="reset-vars" value="reset-vars">
                <i class="far fa-trash-can"></i>
                <span>@T("Admin.Common.Reset")</span>
            </button>

            <zone name="admin_button_toolbar_after"></zone>
        </div>
    </div>

    @if (parsingError.HasValue())
    {
        <div class="mb-5">
            <h4 class="text-danger">@T("Admin.Configuration.Themes.Validation.ErrorReportTitle")</h4>
            <pre>@parsingError</pre>
            <a class="btn btn-danger" href='@Url.Action("Configure", new { theme = Model.ThemeName, storeId = Model.StoreId })'>
                @T("Admin.Configuration.Themes.Validation.RestorePrevValues")
            </a>
        </div>
    }

    <div class="theme-editor">
        @await Component.InvokeAsync("ConfigureTheme", new { theme = Model.ThemeName, storeId = Model.StoreId }) 
    </div>
</form>

<modal id="importvariables-window">
    <modal-header sm-title="@T("Admin.Configuration.Themes.ImportVars")"></modal-header>
    <modal-body>
        <form enctype="multipart/form-data" method="post" asp-action="ImportVariables" asp-route-theme="@Model.ThemeName" asp-route-storeId="@Model.StoreId">
            <p class="text-muted">
                @T("Admin.Configuration.Themes.ImportVars.Note")
            </p>
            <div>
                @T("Admin.Configuration.Themes.ImportVars.XmlFile"): <input type="file" id="importxmlfile" name="importxmlfile" />
            </div>
        </form>
    </modal-body>
    <modal-footer>
        <button type="button" class="btn btn-secondary btn-flat" data-dismiss="modal">
            <span>@T("Admin.Common.Cancel")</span>
        </button>
        <button id="importxmlsubmit" type="button" class="btn btn-primary">
            <span>@T("Common.Import")</span>
        </button>
    </modal-footer>
</modal>

<modal id="exportvariables-window">
    <modal-header sm-title="@T("Admin.Configuration.Themes.ExportVars")"></modal-header>
    <modal-body>
        <form method="post" asp-action="ExportVariables" asp-route-theme="@Model.ThemeName" asp-route-storeId="@Model.StoreId">
            <p class="text-muted">
                @T("Admin.Configuration.Themes.ExportVars.Note")
            </p>
            <div class="form-group m-0">
                <label>@T("Admin.Configuration.Themes.ExportVars.ProfileName") </label>
                <input type="text" class="form-control" name="exportprofilename" placeholder="@T("Common.Optional")" />
            </div>
        </form>
    </modal-body>
    <modal-footer>
        <button type="button" class="btn btn-secondary btn-flat" data-dismiss="modal">
            <span>@T("Admin.Common.Cancel")</span>
        </button>
        <button id="exportxmlsubmit" type="button" class="btn btn-primary">
            <span>@T("Common.Export")</span>
        </button>
    </modal-footer>
</modal>

<script sm-target-zone="scripts" data-origin="configure-theme">
    $(function () {
        // import
        $('#importxmlsubmit').on('click', function (e) {
            e.preventDefault();
            $('#importvariables-window').find("form").submit();
        });

        // export
        $('#exportxmlsubmit').on('click', function (e) {
            e.preventDefault();
            $('#exportvariables-window').modal('hide');
            $('#exportvariables-window').find("form").submit();
        });
    });
</script>